﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace DBLoader
{
    public class PythonProcessHandler : ProcessHandler
    {
        public PythonProcessHandler(PostProcessing proc, int ID, string FileNm)
        {
            Id = ID;
            PostProc = proc;
            CProcess = new Process();
            CProcess.EnableRaisingEvents = true;
            CProcess.Exited += new EventHandler(CProcess_Exited);
            FileName = FileNm;
        }
        private int Id;

        public override void RunProcess()
        {
            CProcess.StartInfo =
                new ProcessStartInfo("cmd", @"/C " + Command);
            //CProcess.StartInfo.RedirectStandardOutput = true;
            CProcess.StartInfo.CreateNoWindow = false;
            CProcess.StartInfo.UseShellExecute = false;
            CProcess.Start();

        }

        public delegate void PostProcessing(int ExitCode,string FileName, int Id, PythonProcessHandler sender);

        PostProcessing PostProc;

        protected override void CProcess_Exited(object sender, EventArgs e)
        {
                PostProc(CProcess.ExitCode, FileName, Id, this);
        }

    }
}
